interface IChatConfig {
  socket: {
    port: number
    path: string
    options: {
      cors: {
        origin: string
        methods: string[]
      }
      pingTimeout: number
      pingInterval: number
    }
  }
  room: {
    limits: {
      maxUsers: number
      maxMessages: number
      messageInterval: number
      userTimeout: number
    }
    filter: {
      customWords: string[]
      whitelistWords: string[]
      xss: {
        whiteList?: Record<string, string[]>
        stripIgnoreTag?: boolean
      }
    }
    frequency: {
      interval: number
      maxMessages: number
    }
    history: {
      maxLength: number
    }
  }
  rocketChat: {
    apiUrl: string
    wsUrl: string
    timeout: number
  }
}

const chatConfig: IChatConfig = {
  socket: {
    port: 3001,
    path: '/socket.io',
    options: {
      cors: {
        origin: '*',
        methods: ['GET', 'POST'],
      },
      pingTimeout: 60000,
      pingInterval: 25000,
    },
  },
  room: {
    limits: {
      maxUsers: 1000,
      maxMessages: 100,
      messageInterval: 1000,
      userTimeout: 30000,
    },
    filter: {
      customWords: ['敏感词1', '敏感词2'],
      whitelistWords: ['允许词1', '允许词2'],
      xss: {
        whiteList: {
          a: ['href', 'title', 'target'],
          img: ['src', 'alt'],
          div: ['class'],
        },
        stripIgnoreTag: true,
      },
    },
    frequency: {
      interval: 60,
      maxMessages: 30,
    },
    history: {
      maxLength: 1000,
    },
  },
  rocketChat: {
    apiUrl: process.env.ROCKET_CHAT_API_URL || 'http://localhost:3000/api',
    wsUrl: process.env.ROCKET_CHAT_WS_URL || 'ws://localhost:3000/ws',
    timeout: 5000,
  },
}

export { IChatConfig, chatConfig }
